<template>
    <div class="det-box">
        <div class="back" @click="router.back()">
            <van-icon name="arrow-left" />
        </div>
        <div class="content" >
            <div class="pic">
                <img :src="goods.img">
            </div>
            <div class="price">
                <span class="l">
                    ￥{{goods.price}}
                    <span>10亿补贴</span>
                </span>
                <span class="m">
                    市场清仓价:
                    <span> ￥4700 </span>
                </span>
                <span class="r">
                    销量:
                    <span> 142 </span>
                </span>
            </div>
            <div class="title">
                <h4>海澜之家</h4>
                <p>{{ goods.title }}</p>
            </div>
            <div class="service">
                <span>选择</span>
                <span class="r">尺码、颜色分类 ></span>
            </div>
            <div class="service">
                <span>服务</span>
                <span class="r">3天无理由退换货·包邮·付款后3-5天内发货</span>
            </div>
            <div class="vip">
                <span>开通黑卡，下单预计省￥30</span>
                <span>立即开卡 ></span>
            </div>
            <div class="installment">
                <h3>全站免息 随心分期</h3>
                <span>分期免息</span>
                <div class="installment_">
                    <p>￥25<span>×3期免息，预计可免1.72元</span></p>
                    <button>免息购买 ></button>
                </div>
            </div>
        </div>
        <van-action-bar>
            <van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" />
            <van-action-bar-icon icon="cart-o" text="购物车" @click="router.push('/bags')"/>
            <van-action-bar-icon icon="star" text="已收藏" color="#ff5000" />
            <van-action-bar-button type="warning" text="加入购物车" @click="addEvt(goods)" />
            <van-action-bar-button type="danger" text="立即购买" />
        </van-action-bar>
    </div>
</template>

<script lang="ts" setup>
import { Ref, ref } from 'vue';
import router from '../../router';
import { cartAddApi, goodsDetailsApi } from '../../apis/goodsApi';
import { useCommonStore } from '../../store';
import { showToast } from 'vant';

/** 商品详情 */
const goodsId:any = sessionStorage.getItem('goodsId')
const goods:Ref<any> = ref([])
goodsEvt()
async function goodsEvt() {
    let res = await goodsDetailsApi(goodsId)
    goods.value = res.data
}

/** 购物车 */
const uid:Ref<string> = useCommonStore().userInfo.id
async function addEvt(data: any) {
    let addArr:Ref<CartInfo> = {...data,uid,pcount:1,pid: data.id}
    let res = await cartAddApi(addArr)
    if(res.code === 200) {
        showToast('加入购物车成功')
    }
}
</script>

<style lang="less" scoped>
@import '../../style/common.less';

.det-box {
    width: 100vw;
    height: 100vh;

    .back {
        position: fixed;
        top: 20px;
        left: 20px;
        width: 30px;
        height: 30px;
        background-color: @c4;
        text-align: center;
        border-radius: 50%;
        padding-right: 4px;

        .van-icon {
            color: @g1;
            font-size: 24px;
            line-height: 28px;
        }
    }

    .content {
        width: 100%;
        height: calc(100% - 50px);
        background-color:#f0eff4 ;
        overflow-x: hidden;
        &::-webkit-scrollbar {
            display: none;
        }

        .pic {
            width: 100%;
            height: 390px;

            img {
                width: 100%;
                height: 390px;
            }
        }

        .price {
            width: 100%;
            font-size: 14px;
            display: flex;
            justify-content: space-around;
            align-items: baseline;
            padding: 0 10px;
            background-color: @g1;

            
            .l {
                font-size: 24px;
                font-weight: bolder;

                span {
                    font-size: 12px;
                    color: red;
                    border: 2px solid red;
                    border-radius: 10px;
                    padding: 2px;
                    vertical-align: middle;
                }
            }

            .m {
                color: darkgray;

                span {
                    text-decoration: line-through;
                }
            }
        }

        .title {
            width: 100%;
            padding: 0 10px;
            background-color: @g1;
            padding-bottom: 16px;
            margin-bottom: 10px;


            h4 {
                line-height: 40px;
            }

            p {
                text-indent: 2rem;
                font-size: 18px;
            }
        }

        .service {
            width: 100%;
            height: 50px;
            background-color: @g1;
            border-bottom: 1px solid #cccccc;
            padding: 0 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 14px;
            font-weight: bolder;

            .r {
                font-weight: normal;
                color: @g4;
            }
        }

        .vip {
            width: 100%;
            height: 50px;
            background-color: #4B3F40;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 10px;
            font-size: 14px;
            border-radius: 10px;
            margin: 10px 0;
            color: #C5B9AB;
        }

        .installment{
            width: 100%;
            height: 120px;
            background-color: @g1;
            padding: 20px 10px;

            h3 {
                display: inline;
                color: #DE8848;
                
            }

            span {
                font-size: 16px;
                color: darkgray;
                margin-left: 10px;
            }

            .installment_{
                width: 100%;
                height: 44px;
                margin-top: 6px;
                display: flex;
                align-items: end;
                justify-content: space-between;
                
                p {
                    font-weight: bolder;
                    font-size: 24px;
                    span {
                        margin-left: 0px;
                        color: @c2;
                    }
                }

                button {
                    width: 100px;
                    height: 44px;
                    background-color: #DE8848;
                    border: none;
                    color: @g1;
                    font-size: 14px;
                    border-radius: 6px;
                }
            }
        }
    }
}
</style>

